package com.atguigu.admin.acutuator.health;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 杨林
 * @create 2023-09-06 16:50 星期三
 * description:
 */
@Component
public class MyComHealthIndicator extends AbstractHealthIndicator {

    /**
     * 真实的检查方法
     * @param builder
     * @throws Exception
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {

        //模拟需要返回的数据
        Map<String,Object> map = new HashMap<>();
        
        if (1==1){
//            builder.up();   //健康
            builder.status(Status.UP);
            map.put("count",1);
            map.put("ms",1000);
        }else {
//            builder.down();
            builder.status(Status.OUT_OF_SERVICE);
            map.put("msg","连接超时");
        }
        
        builder.withDetail("code",100).withDetails(map);
    }
}
